package com.magic.blog.config;

import com.jagregory.shiro.freemarker.ShiroTags;
import com.magic.blog.template.HotsTemplate;
import com.magic.blog.template.PostsTemplate;
import com.magic.blog.template.TimeAgoMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * created by mzk on 2020/07/25
 */
@Configuration
public class FreemarkerConfig {
    @Autowired
    private freemarker.template.Configuration configuration;

    @Autowired
    private PostsTemplate postsTemplate;

    @Autowired
    private HotsTemplate hotsTemplate;

    @PostConstruct
    public void  setUp(){
        configuration.setSharedVariable("timeAgo",new TimeAgoMethod());
        configuration.setSharedVariable("posts",postsTemplate);
        configuration.setSharedVariable("hots",hotsTemplate);
        configuration.setSharedVariable("shiro",new ShiroTags());
    }
}
